//
//  DetailViewController.swift
//  2-08-实战演练
//
//  Created by 范英强 on 16/1/26.
//  Copyright © 2016年 范英强. All rights reserved.
//

import UIKit

class DetailViewController: UIViewController {

    var saveCallback: (() -> ())?
    @IBAction func txtdid(sender: UITextField) {
        navigationItem.rightBarButtonItem?.enabled = (textName.hasText() && txtAge.hasText())
    }
    @IBOutlet weak var txtAge: UITextField!

    
    @IBOutlet weak var textName: UITextField!
    var person: Person?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        print(person?.name)
        
        textName.text = person?.name
        txtAge.text = "\(person?.age ?? 0)"
    }

    @IBAction func saveClick(sender: AnyObject) {
        person?.name = textName.text
        person?.age = Int(txtAge.text!) ?? 0
        saveCallback?()
        navigationController?.popViewControllerAnimated(true)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
